package cn.dnui_yxk801.dnuifood_16110100801.controller;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import cn.dnui_yxk801.dnuifood_16110100801.R;
import cn.dnui_yxk801.dnuifood_16110100801.bean.UserBean;
import cn.dnui_yxk801.dnuifood_16110100801.listener.OnRetrofitListener;
import cn.dnui_yxk801.dnuifood_16110100801.model.UserModel;

import static cn.dnui_yxk801.dnuifood_16110100801.MainActivity.userid;


/**
 * A simple {@link Fragment} subclass.
 */
public class Fragment4 extends Fragment implements OnRetrofitListener{
    private TextView Mine_tv_name;
    private TextView Mine_tv_telnum;
    private ImageView Mine_iv_pic;
    private CardView Mine_cv_dingdan;
    private CardView Mine_cv_comment;
    private ImageView Mine_iv_update;
    private View view;

    public Fragment4() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment4, container, false);
        initViews();
        initEvents();
        initdatas();
        return view;
    }
    private void initViews(){
        Mine_tv_name=view.findViewById(R.id.Mine_tv_name);
        Mine_tv_telnum=view.findViewById(R.id.Mine_tv_telnum);
        Mine_iv_pic=view.findViewById(R.id.Mine_iv_pic);
        Mine_cv_dingdan=view.findViewById(R.id.Mine_cv_dingdan);
        Mine_cv_comment=view.findViewById(R.id.Mine_cv_comment);
        Mine_iv_update=view.findViewById(R.id.Mine_iv_update);
    }
    private void initEvents(){
        Mine_cv_dingdan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(),MyOrderActivity.class);
                startActivity(intent);
            }
        });

        Mine_cv_comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(),MyCommentsActivity.class);
                startActivity(intent);
            }
        });
        Mine_iv_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(),UpdateUserActivity.class);
                startActivity(intent);
            }
        });
    }
    private void initdatas(){
        UserModel userModel=new UserModel();
        userModel.getUserById(userid,this);

    }

    @Override
    public void onSuccess(Object object, int flag) {
        if (flag==9){
            UserBean userBean=(UserBean)object;
            Mine_tv_name.setText(userBean.getUsername());
            Mine_tv_telnum.setText(userBean.getMobilenum());
        }
    }

    @Override
    public void onFalure(String msg) {

    }


}
